package eu.vranckaert.calendar.test;

import android.app.Activity;
import android.os.Bundle;
import eu.vranckaert.calendar.CalendarDayView;
import eu.vranckaert.calendar.CalendarViewHelper;
import eu.vranckaert.calendar.widget.Workspace;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Date: 12/03/13
 * Time: 9:13
 *
 * @author Dirk Vranckaert
 */
public class FixedDaysViewActivity extends Activity implements CalendarDayView.OnDataLoadListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.day_view);

        Workspace workspace = (Workspace) findViewById(R.id.workspace);
        CalendarViewHelper.initCalendarFixedDays(this, workspace, new Date(), -3, R.color.block_color, this);
    }

    @Override
    public List<MyTimeEntity> loadDataForDay(Date day) {
        List<MyTimeEntity> timeBlocks = new ArrayList<MyTimeEntity>();

        // Can be a database call here, for this demo we only display blocks on even days
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(day);


        MyTimeEntity te1 = new MyTimeEntity();
        te1.setStartTime(getTimeForDay(10, 0, day));
        te1.setEndTime(getTimeForDay(11, 30, day));
        MyTimeEntity te2 = new MyTimeEntity();
        te2.setStartTime(getTimeForDay(11, 30, day));
        te2.setEndTime(getTimeForDay(12, 0, day));
        MyTimeEntity te3 = new MyTimeEntity();
        te3.setStartTime(getTimeForDay(13, 0, day));
        te3.setEndTime(getTimeForDay(16, 0, day));
        MyTimeEntity te4 = new MyTimeEntity();
        te4.setStartTime(getTimeForDay(16, 45, day));
        te4.setEndTime(getTimeForDay(17, 0, day));
        MyTimeEntity te5 = new MyTimeEntity();
        te5.setStartTime(getTimeForDay(17, 0, day));
        te5.setEndTime(getTimeForDay(17, 15, day));
        MyTimeEntity te6 = new MyTimeEntity();
        te6.setStartTime(getTimeForDay(17, 15, day));
        te6.setEndTime(getTimeForDay(18, 45, day));

        timeBlocks.add(te1);
        timeBlocks.add(te2);
        timeBlocks.add(te3);
        timeBlocks.add(te4);
        timeBlocks.add(te5);
        timeBlocks.add(te6);

        return timeBlocks;
    }

    private Date getTimeForDay(int hour, int minute, Date day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        return calendar.getTime();
    }
}
